package cn.livingCloud.dto;

import cn.livingCloud.entity.user.Member;
import cn.livingCloud.utils.DateUtils;
import org.apache.commons.lang.StringUtils;

/**
 * Created by DingJie  on 2015/12/25.
 */
public class MemberDto {
    private String uuid;
    private String openid;//用户的唯一标识
    private String nickname;//用户昵称
    private String sex;//用户的性别，值为1时是男性，值为2时是女性，值为0时是未知
    private String province;//用户个人资料填写的省份
    private String city;//普通用户个人资料填写的城市
    private String country;//国家，如中国为CN
    private boolean state;//状态
    //创建时间
    //yyyy-MM-dd HH:mm:ss
    private String createTime;
    private String headimgurl;
    private String address;

    public MemberDto(Member member) {
        if (member == null) {
            return;
        }
        this.uuid = member.getUuid();
        this.openid = member.getOpenid();
        this.nickname = member.getNickname();
        this.sex = member.getSex();
        this.province = member.getProvince();
        this.city = member.getCity();
        this.country = member.getCountry();
        this.state = member.isState();
        this.createTime = DateUtils.toDateText(member.getCreateTime(), DateUtils.DEFAULT_DATE_TIME_FORMAT);
        this.headimgurl = member.getHeadimgurl();
        StringBuilder address = new StringBuilder();
        if (StringUtils.isNotEmpty(country)) {
            address.append(country);
        }
        if (StringUtils.isNotEmpty(province)) {
            address.append(province);
        }
        if (StringUtils.isNotEmpty(city)) {
            address.append(city);
        }
        this.address = address.toString();

    }

    public MemberDto() {
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getShortNickName() {
        if (nickname.length() > 4) {
            return nickname.substring(0, 3) + "..";
        }
        return nickname;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getOpenid() {
        return openid;
    }

    public void setOpenid(String openid) {
        this.openid = openid;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public boolean isState() {
        return state;
    }

    public void setState(boolean state) {
        this.state = state;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getHeadimgurl() {
        return headimgurl;
    }

    public MemberDto setHeadimgurl(String headimgurl) {
        this.headimgurl = headimgurl;
        return this;
    }

    public String getAddress() {
        return address;
    }

    public MemberDto setAddress(String address) {
        this.address = address;
        return this;
    }
}
